import dash
import pandas as pd
from dash import html
import feffery_antd_components as fac
from dash.dependencies import Input, Output

app = dash.Dash(__name__)

demo_df = pd.DataFrame({
    '字段1': range(20),
    '字段2': pd.date_range('2022-01-01 00:00:00', '2022-01-20 00:00:00')
})

# 转换为日期时间字符串
demo_df['字段2'] = demo_df['字段2'].dt.strftime('%Y-%m-%d %H:%M:%S')

app.layout = html.Div(
    [
        fac.AntdTable(
            id='table-editable-demo',
            columns=[
                {
                    'title': '字段1',
                    'dataIndex': '字段1'
                },
                {
                    'title': '字段2',
                    'dataIndex': '字段2',
                    'editable': True
                }
            ],
            data=demo_df.to_dict('records'),
            bordered=True,
            columnsFormatConstraint={
                '字段2': {
                    'rule': '^\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}$',
                    'content': '不符日期时间型格式要求！'
                }
            }
        )
    ],
    style={
        'padding': '100px'
    }
)

if __name__ == '__main__':
    app.run_server(debug=True)
